#!/usr/bin/env node
const http=require('http'),
      log=console.log;
http.createServer((req,res)=>{
  if(req.url!='/'){
    err(res);
    return
  }else{
    if(req.method!='POST'){
      err(res)
    }else{
      req.pipe(process.stdout);
      res.end('ok!');
      log(`${req.method} ${req.url} HTTP/${req.httpVersion}`);
      log(req.headers);
      log('');
    }

}).listen(8080);
function err(res){
  let msg='Not found!';
  res.statusCode=404;
  res.setHeader('Content-Length',msg.length);
  res.setHeader('Contnet-Type','text/plain');/*Content-Type用于定义网络文件的类型和网页的编码，决定浏览器将以什么形式、什么编码读取这个文件
  text/html  :Html格式
  test/plain:纯文本格式
  */
  res.end(msg);

}
console.log('hello world');
